package com.phb.puhuibao.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.idp.pub.dao.IBaseDao;
import com.idp.pub.dao.IPagerDao;
import com.idp.pub.service.impl.DefaultBaseService;
import com.phb.puhuibao.entity.ParTimeJobType;
import com.phb.puhuibao.service.ParTimeJobTypeService;

@Transactional
@Service("parTimeJobTypeService")
public class ParTimeJobTypeServiceImpl extends DefaultBaseService<ParTimeJobType, String> implements ParTimeJobTypeService{
	@Resource(name = "parTimeJobTypeDao")
	public void setBaseDao(IBaseDao<ParTimeJobType, String> baseDao) {
		super.setBaseDao(baseDao);
	}

	@Resource(name = "parTimeJobTypeDao")
	public void setPagerDao(IPagerDao<ParTimeJobType> pagerDao) {
		super.setPagerDao(pagerDao);
	}
	@Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	
	@Override
	public List<Map<String, Object>> getParTimeJobsTypeSubordinate() {

		try {
			List <Map<String, Object>> list = null;
			String sql="SELECT a.parttime_job_id,a.job_classtype FROM phb_part_time_job a WHERE a.job_status=1";
			list = this.jdbcTemplate.queryForList(sql);
			List<Map<String, Object>> list3=new ArrayList();
			for (Map<String, Object> map : list) {
				String jobClasstype = (String) map.get("job_classtype");
				Map<String, Object> params = new HashMap<String, Object>();
				int parttimeJobId = (int) map.get("parttime_job_id");
				List <Map<String, Object>> list1 = null;
				String sql1="SELECT a.job_type_type,a.parttime_job_type_id  FROM phb_part_time_job_type a WHERE a.type_status=1 AND a.parttime_job_id="+parttimeJobId+"";
				list1 = this.jdbcTemplate.queryForList(sql1);
				List<Map<String, Object>> list2=new ArrayList();
				for (Map<String, Object> map1 : list1) {
					Map<String, Object> params1 = new HashMap<String, Object>();
					String jobTypeType = (String) map1.get("job_type_type");
					int parttimeJobTypeId = (int) map1.get("parttime_job_type_id");
					params1.put("jobTypeType", jobTypeType);
					params1.put("parttimeJobTypeId", parttimeJobTypeId);
					list2.add(params1);
				}
				params.put("jobClasstype", jobClasstype);
				params.put("parttimeJobId", parttimeJobId);
				params.put("jobTypeSubordinate", list2);
				list3.add(params);
			}
			return list3;
		} catch (Exception e) {
			return null;
		}
		
	}

	
	
}
